/*
 * ArithmeticUnit.cpp
 *
 *  Created on: 2012-5-20
 *      Author: WuyaMony
 */
#include"ArithmeticUnit.h"
namespace my {

my::ArithmeticUnit::ArithmeticUnit(deque<int>&data, int step,int (*func)(int,int)) :
		_data(data), _step(step), _func(func),taskNum(0) {
	t.isCalc = false;
	for (int i = 1; i < step; ++i) {
		_calc.push_back(t);
	}
}
void my::ArithmeticUnit::addTask(int a, int b) {
	taskNum++;
	t.isCalc = true;
	t.a = a;
	t.b = b;
	cout << "\tadd task" << t.a << "," << t.b << endl;
}

void my::ArithmeticUnit::Tick() {
	_calc.push_back(t);
	t.isCalc = false;
	Task &tmp = _calc.front();
	if (tmp.isCalc) {
		_data.push_back(_func(tmp.a ,tmp.b));
		taskNum--;
	}
	_calc.pop_front();
}
}
